import myRequest from '../request.js'
import dicts from '@/config/dicts.js'

// 获取用户协议
export const getAgreementList = () => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.essential + '/common/agreement', 'get').then(res => {
      resolve(res)
    }).catch((err) => {
      reject(err)
    })
  })
}
// 获取用户协议内容
export const getAgreementContent = (id) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.essential + `/common/agreement/${id}/content`, 'get')
      .then(res => {
        resolve(res)
      }).catch((err) => {
        reject(err)
      })
  })
}
export const submitRegistration = (params) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + '/purchaser/permit/member/register', 'post', params)
      .then(res => {
        resolve(res)
      }).catch((err) => {
        reject(err)
      })
  })
}
// 手机验证码
// LOGIN 登录,REGISTER 注册,FIND_USER 找回,UPDATE_PASSWORD 改密,WALLET_PASSWORD 钱包密码
export const getCode = (verificationEnums, mobile) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.essential + `/common/common/sms/${verificationEnums}/${mobile}`, 'get')
      .then(res => {
        resolve(res)
      }).catch((err) => {
        reject(err)
      })
  })
}
// 获取采购商类型列表
export const getPurchaser = () => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + '/purchaser/purchaser/molds', 'post').then(res => {
      resolve(res)
    }).catch((err) => {
      reject(err)
    })
  })
}
// 获取采购商公司信息
export const getPurchaserInfo = (id) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + `/purchaser/purchaser/purchaser/${id}`, 'get')
      .then(res => {
        resolve(res)
      }).catch((err) => {
        reject(err)
      })
  })
}
// 提交类型
export const setPurchaser = (val) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + `/purchaser/purchaser/purchaser/changeMold`, 'put', val)
      .then(res => {
        resolve(res)
      }).catch((err) => {
        reject(err)
      })
  })
}
// 获取配置
export const getClassification = (purchaserId) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + `/purchaser/purchaser/purchaser/${purchaserId}/materials/preview`, 'get')
      .then(res => {
        resolve(res)
      }).catch((err) => {
        reject(err)
      })
  })
}
// 获取配置信息
export const getClassificationConfig = (purchaserId, classificationId) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + `/purchaser/purchaser/purchaser/${purchaserId}/material/${classificationId}`, 'get')
      .then(res => {
        resolve(res)
      }).catch((err) => {
        reject(err)
      })
  })
}
// 获取省市信息
export const getRegion = () => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.essential + `/common/common/region/allCity`, 'get').then(res => {
      resolve(res)
    }).catch((err) => {
      reject(err)
    })
  })
}
// 获取区信息
export const getRegionItem = (id) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.essential + `/common/common/region/item/${id}`, 'get').then(res => {
      resolve(res)
    }).catch((err) => {
      reject(err)
    })
  })
}
// 提交资质信息
export const preserveClassification = (purchaserId, classificationId, val) => {
  return new Promise((resolve, reject) => {
    myRequest(
      dicts.buyer + `/purchaser/purchaser/purchaser/${purchaserId}/material/${classificationId}`,
      'post', val, { 'Content-type': "application/json" }
    ).then(res => {
      resolve(res)
    }).catch((err) => {
      reject(err)
    })
  })
}
// 识图
export const getIdentify = (val) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.essential + `/common/common/ocr/identify/image`, 'get', val)
      .then(res => {
        resolve(res)
      }).catch((err) => {
        reject(err)
      })
  })

}
// 提交 资质审核
export const auditing = (purchaserId) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.buyer + `/purchaser/purchaser/purchaser/${purchaserId}/materials/review`, 'put')
      .then(res => {
        resolve(res)
      }).catch((err) => {
        reject(err)
      })
  })
}
// 上传图片  文件
export const uploadImage = (val) => {
  return new Promise((resolve, reject) => {
    myRequest(dicts.essential + `/common/common/upload/file`, 'post', val, { "Content-type": "multipart/form-data;charset=UTF-8" })
      .then(res => {
        resolve(res)
      }).catch((err) => {
        reject(err)
      })
  })
}